Fix PR comments
authorKarol Kuczmarski <karol.kuczmarski@gmail.com>
Fri, 12 May 2017 20:47:28 +0000 (21:47 +0100)
committerKarol Kuczmarski <karol.kuczmarski@gmail.com>
Fri, 12 May 2017 20:47:28 +0000 (21:47 +0100)
src/cargo/ops/cargo_compile.rs
src/cargo/ops/cargo_rustc/mod.rs
tests/build-script.rs

index ef5aa927499e98449357cc2e379a59db23c8b364..861f95bd726f61940cb8534628050c3ca5e9be00 100644 (file)
@@ -709,6 +709,12 @@ fn scrape_target_config(config: &Config, triple: &str)
                     let list = value.list(&k)?;
                     output.cfgs.extend(list.iter().map(|v| v.0.clone()));
                 }
+                "rustc-env" => {
+                    for (name, val) in value.table(&k)?.0 {
+                        let val = val.string(name)?.0;
+                        output.env.push((name.clone(), val.to_string()));
+                    }
+                }
                 "warning" | "rerun-if-changed" => {
                     bail!("`{}` is not supported in build script overrides", k);
                 }
index 9d9c56d2c1977cf06da06687b777accaaf0a8a2b..bf46397c7a748daf6afa2f99faa7e8751eb2d0f0 100644 (file)
@@ -428,17 +428,12 @@ fn rustc(cx: &mut Context, unit: &Unit, exec: Arc<Executor>) -> CargoResult<Work
     // been put there by one of the `build_scripts`) to the command provided.
     fn add_custom_env(rustc: &mut ProcessBuilder,
                       build_state: &BuildMap,
-                      build_scripts: &BuildScripts,
+                      _: &BuildScripts,
                       current_id: &PackageId) -> CargoResult<()> {
-        for key in build_scripts.to_link.iter() {
-            let output = build_state.get(key).chain_error(|| {
-                internal(format!("couldn't find build state for {}/{:?}",
-                                 key.0, key.1))
-            })?;
-            if key.0 == *current_id {
-                for &(ref name, ref value) in output.env.iter() {
-                    rustc.env(name, value);
-                }
+        let key = (current_id.clone(), Kind::Host);
+        if let Some(output) = build_state.get(&key) {
+            for &(ref name, ref value) in output.env.iter() {
+                rustc.env(name, value);
             }
         }
         Ok(())
index e663f5abc923d87cd414f52a2dac66b0614e5467..31dbd7b466a5259bf1e6410f5e8c98bcc94fe8ef 100644 (file)
@@ -1587,7 +1587,9 @@ fn env_build() {
         "#)
         .file("src/main.rs", r#"
             const FOO: &'static str = env!("FOO");
-            fn main() {}
+            fn main() {
+                println!("{}", FOO);
+            }
         "#)
         .file("build.rs", r#"
             fn main() {
@@ -1596,6 +1598,8 @@ fn env_build() {
         "#);
     assert_that(build.cargo_process("build").arg("-v"),
                 execs().with_status(0));
+    assert_that(build.cargo("run").arg("-v"),
+                execs().with_status(0).with_stdout("foo\n"));
 }
 
 #[test]